package arrays_;

import java.util.Arrays;
import java.util.Comparator;

/**
 * @author wly
 * @version V1.0.0
 * @date 2022/12/23 19:01
 */
public class ArraysExercise01 {
    public static void main(String[] args) {
        Book[] books = new Book[4];
        books[0] = new Book("红楼梦", 100.01);
        books[1] = new Book("金瓶梅", 90.9);
        books[2] = new Book("青年文摘", 5.5);
        books[3] = new Book("爱说大话", 333.3);
        Arrays.sort(books, new Comparator<Book>() {
            @Override
            public int compare(Book o2, Book o1) {
                return (int)(o1.getPrice() - o2.getPrice());
            }
        });
        System.out.println(Arrays.toString(books));
    }
}

class Book{
    private String name;
    private double price;

    public double getPrice() {
        return price;
    }

    public Book(String name, double price) {
        this.name = name;
        this.price = price;
    }

    @Override
    public String toString() {
        return "Book{" +
                "name='" + name + '\'' +
                ", price=" + price +
                '}';
    }
}
